package com.yulan.bankback.service.bank.impl;

import com.aliyun.oss.ClientException;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.yulan.bankback.service.bank.AliyunSmsService;
import org.springframework.stereotype.Service;

@Service
public class AliyunSmsServiceImpl implements AliyunSmsService {

    @Override
    public void sendMsg(String phone, String msg) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4FcG61aVXq8uCt1qUE95", "tdIz6Ft85nshNMImWYr8jDNec8Vxz7");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", "YuLanGo");
        request.putQueryParameter("TemplateCode", "SMS_182679543");
        request.putQueryParameter("TemplateParam", "{code: " + msg + "}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ClientException | com.aliyuncs.exceptions.ClientException e) {
            e.printStackTrace();
        }

    }
}
